package priv.pront.code.robot.roboCom_uni;

import priv.pront.code.lanqiao.competition.course.date0401.Main;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

/**
 * @Description:
 * @Author: pront
 * @Time:2023-07-06 14:30
 */
public class P8630_密文搜索 {

    public static void getResult(String A, String[] pwd) {
        int count = 0;
        ArrayList<Integer> list = new ArrayList<>();
        int[] num = new int[pwd.length];
        for(int i = 0;i < pwd.length;i++) {
            int hash = pwd[i].hashCode();
            if(list.contains(hash)) {
                int j = list.indexOf(hash);
                num[j]++;
            } else {
                list.add(hash);
                num[list.size() - 1]++;
            }
        }
        for(int i = 0;i <= A.length() - 8;i++) {
            String s = A.substring(i, i + 8);
            char[] temp = s.toCharArray();
            Arrays.sort(temp);
            StringBuffer t = new StringBuffer("");
            for(int j = 0;j < 8;j++)
                t.append(temp[j]);
            s = t.toString();
            int hash = s.hashCode();
            if(list.contains(hash)) {
                int k = list.indexOf(hash);
                count = count + num[k];
            }
        }
        System.out.println(count);
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String A = in.next();
        int n = in.nextInt();
        String[] pwd = new String[n];
        for(int i = 0;i < n;i++) {
            char[] arrayP = in.next().toCharArray();
            Arrays.sort(arrayP);
            StringBuffer s = new StringBuffer("");
            for(int j = 0;j < arrayP.length;j++)
                s.append(arrayP[j]);
            pwd[i] = s.toString();
        }
        P8630_密文搜索.getResult(A, pwd);
    }
}
